﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MainFrame
{
    public partial class PageVersion : Form
    {
        public PageVersion()
        {
            InitializeComponent();
        }
        bool isfirst = true;
        private void PageVersion_Load(object sender, EventArgs e)
        {
            if (isfirst)
            {
                isfirst = false;
                ReadTypeFile();
                if (GlobalVar.tv_list.Count > 0)
                    cbo_type_selectType.Items.AddRange(GlobalVar.tv_list.Select(a => a.type).Distinct().ToArray());
                ChangeType(GlobalVar.closeSave.CurrentTypeName);
                this.cbo_selectVersion.SelectedIndexChanged += new System.EventHandler(this.cbo_selectVersion_SelectedIndexChanged);
                this.cbo_type_selectType.SelectedIndexChanged += new System.EventHandler(this.cbo_type_selectType_SelectedIndexChanged);
                //var plcList = new ContextMenuStrip();
                //var zoomAdd = new ToolStripMenuItem("新增行");
                //zoomAdd.Click += new System.EventHandler(this.dgv_type_addRow_Click);
                //plcList.Items.Add(zoomAdd);
                //var zoomDelete = new ToolStripMenuItem("删除选中行");
                //zoomDelete.Click += new System.EventHandler(this.dgv_type_DeleteRow_Click);
                //plcList.Items.Add(zoomDelete);
                //dgv_type.ContextMenuStrip = plcList;


                //var plcList2 = new ContextMenuStrip();
                //var zoomAdd2 = new ToolStripMenuItem("新增行");
                //zoomAdd2.Click += new System.EventHandler(this.dgv_version_addRow_Click);
                //plcList2.Items.Add(zoomAdd2);
                //var zoomDelete2 = new ToolStripMenuItem("删除选中行");
                //zoomDelete2.Click += new System.EventHandler(this.dgv_version_DeleteRow_Click);
                //plcList2.Items.Add(zoomDelete2);
                //dgv_version.ContextMenuStrip = plcList2;
                GlobalVar.ChangeModel += ChangeType;
            }
           
            RefreshTable(GlobalVar.closeSave.CurrentTypeName);
        }
        private void RefreshTable(string typeVersion)
        {
           
            if(!string.IsNullOrEmpty(typeVersion)&&typeVersion.Contains(GlobalVar.char_VersionSpilt))
            {
                var arr_typeVersion = typeVersion.Split(GlobalVar.char_VersionSpilt);
                var curType = "";
                var curVersion = "";
                int curTypeIndex = 0;
                int curVersionIndex = 0;
                if (arr_typeVersion.Length > 0)
                {
                    curType = arr_typeVersion[0];
                    curVersion = arr_typeVersion[1];
                }
                dgv_type.Rows.Clear();
                int rowIndex = 0;
                GlobalVar.tv_list.Select(a => a.type).Distinct().ToList().ForEach(
                    curT =>
                    {
                        if (curType == curT)
                            curTypeIndex = rowIndex;
                        rowIndex++;
                        dgv_type.Rows.Add(new object[] { rowIndex, curT });
                    });
                if (dgv_type.Rows.Count > curTypeIndex)
                    dgv_type.CurrentCell = dgv_type.Rows[curTypeIndex].Cells[0];


                rowIndex = 0;
                dgv_version.Rows.Clear();
                
                GlobalVar.tv_list.ForEach(cur =>
                {
                    if (curType == cur.type && curVersion == cur.Version)
                        curVersionIndex = rowIndex;
                    rowIndex++;
                    dgv_version.Rows.Add(new object[] { rowIndex, cur.type, cur.Version });

                });
                if (dgv_version.Rows.Count > curVersionIndex)
                    dgv_version.CurrentCell = dgv_version.Rows[curVersionIndex].Cells[0];
                cbo_selectVersion.Items.Clear();
                cbo_type_selectType.Items.Clear();
                cbo_type_selectType.Items.AddRange(GlobalVar.tv_list.Select(a => a.type).Distinct().ToArray());
                ChangeType(GlobalVar.closeSave.CurrentTypeName);
                GlobalVar.RefreshModel?.Invoke(GlobalVar.closeSave.CurrentTypeName);
            }
         
        }

        private void dgv_type_addRow_Click(object sender, EventArgs e)
        {
            dgv_type.Rows.Add(new object[] { dgv_type.Rows.Count + 1, "" });
        }
        private void dgv_type_DeleteRow_Click(object sender, EventArgs e)
        {
            if (dgv_type.SelectedRows.Count > 0)
            {
                if (DialogResult.Yes == MessageBox.Show("确定要删除选中行？", "询问", MessageBoxButtons.YesNo))
                    dgv_type.Rows.Remove(dgv_type.SelectedRows[0]);
            }

        }
        private void dgv_version_addRow_Click(object sender, EventArgs e)
        {
            dgv_version.Rows.Add(new object[] { dgv_version.Rows.Count + 1, "", ""});
        }
        private void dgv_version_DeleteRow_Click(object sender, EventArgs e)
        {
            if (dgv_version.SelectedRows.Count > 0)
            {
                if (DialogResult.Yes == MessageBox.Show("确定要删除选中行？", "询问", MessageBoxButtons.YesNo))
                    dgv_version.Rows.Remove(dgv_version.SelectedRows[0]);
            }

        }
        private void ReadTypeFile()
        {
            try
            {

                if (!Directory.Exists(GlobalVar.type_path))
                {
                    return;
                }
                DirectoryInfo dif = new DirectoryInfo(GlobalVar.type_path);
                var arr_fileName = dif.GetFiles();
                foreach (var item in arr_fileName)
                {
                    if (item.Extension == ".tfp")
                    {
                        var str_type = item.Name.Replace(".tfp", "");
                        var arr_type = str_type.Split('~');
                        var curType = new typeVersion() { type = arr_type[0] };
                        if (arr_type.Length > 1)
                        {
                            curType.Version = arr_type[1];
                        }
                        GlobalVar.tv_list.Add(curType);
                    }
                }
              
            }
            catch (System.Exception ex)
            {
                displalyInfo.displayInfoMain($"添加型号到列表出错:{ex.Message}");
            }
        }
        private int ChangeType(string typeVersion)
        {
            if (cbo_type_selectType.Items.Count > 0)
            {
                if (!string.IsNullOrEmpty(typeVersion))
                {
                    
                    var arr_type = typeVersion.Split(GlobalVar.char_VersionSpilt);
                    cbo_type_selectType.SelectedItem = arr_type[0];
                    var lst_cur = GlobalVar.tv_list.Where(a => a.type == arr_type[0] && !string.IsNullOrEmpty(a.Version)).Select(a => a.Version).ToList();
                    cbo_selectVersion.Items.Clear();
                    if (lst_cur.Count > 0)
                    {
                        cbo_selectVersion.Items.AddRange(lst_cur.ToArray());
                    }
                    if (arr_type.Length > 1)
                    {
                        if (lst_cur.Contains(arr_type[1]))
                        {
                            cbo_selectVersion.SelectedItem = arr_type[1];
                        }
                        else
                        {
                            if (lst_cur.Count > 0)
                            {
                                cbo_selectVersion.SelectedIndex = 0;
                            }
                        }
                    }
                    else
                    {
                        if (lst_cur.Count > 0)
                        {
                            cbo_selectVersion.SelectedIndex = 0;
                        }
                    }
                    
                }
                else
                {
                    cbo_type_selectType.SelectedIndex = 0;
                }
                if ( !string.IsNullOrEmpty(typeVersion))
                {
                    GlobalVar.closeSave.CurrentTypeName = typeVersion;
                }
            }
            if (cbo_type_selectType.SelectedItem != null)
            {
                GlobalVar.motionConfig = (MotionConfig)SerializeHelper.DeserializeFile<MotionConfig>(GlobalVar.type_path + "\\" + GlobalVar.closeSave.CurrentTypeName + ".tfp", "型号参数");//运动参数反序列化
                if (GlobalVar.motionConfig == null)
                {
                    GlobalVar.motionConfig = new MotionConfig();
                }
                return 1;
            }
            else
                return -1;

        }
        private void saveType()
        {
            try
            {
                var curType = cbo_type_selectType.Text.Trim();
                var curVision = cbo_selectVersion.Text.Trim();
                if (!cbo_type_selectType.Items.Contains(curType))
                {
                    cbo_type_selectType.Items.Add(curType);
                }
                if (!cbo_selectVersion.Items.Contains(curVision))
                {
                    cbo_selectVersion.Items.Add(curVision);
                }
                if (GlobalVar.motionConfig == null)
                {
                    GlobalVar.motionConfig = new MotionConfig();
                }
                if (!Directory.Exists(GlobalVar.type_path))
                {
                    Directory.CreateDirectory(GlobalVar.type_path);
                }
                if (!Directory.Exists(GlobalVar.type_copy_path))
                {
                    Directory.CreateDirectory(GlobalVar.type_copy_path);
                }
                GlobalVar.closeSave.CurrentTypeName = curType + GlobalVar.char_VersionSpilt + curVision;
                SerializeHelper.serializeFile(GlobalVar.type_path + "\\" + GlobalVar.closeSave.CurrentTypeName + ".tfp", GlobalVar.motionConfig, GlobalVar.closeSave.CurrentTypeName);
                SerializeHelper.serializeFile(GlobalVar.type_copy_path + "\\" + GlobalVar.closeSave.CurrentTypeName + ".tfp", GlobalVar.motionConfig, GlobalVar.closeSave.CurrentTypeName);

            }
            catch (System.Exception ex)
            {
                displalyInfo.displayInfoMain($"型号数据保存出错:{ex.Message}");
            }
        }
        private void btn_Confirm_Click(object sender, EventArgs e)
        {

            var curType = cbo_type_selectType.Text.Trim();
            var curVersion = cbo_selectVersion.Text.Trim();
            if (string.IsNullOrEmpty(curType) || string.IsNullOrEmpty(curVersion))
            {
                return;
            }
            var curlist = GlobalVar.tv_list.Where(a => a.type == curType && a.Version == curVersion).ToList();
            if (curlist.Count < 1)
            {
                MessageBox.Show("产品名称 产品型号 不存在");
                return;
            }
            if (curlist[0].GetTypeVersion() == GlobalVar.closeSave.CurrentTypeName)
            {
                MessageBox.Show("产品名称 产品型号 不存在");
                return;
            }
            if (GlobalVar.isAutoRun)
            {
                MessageBox.Show("机器自动状态下不能切换产品");
                return;
            }
            try
            {
                PageVersionConfirm confirm = new PageVersionConfirm(curlist[0].GetTypeVersion());
                confirm.ShowDialog();
            }
            catch(Exception ex)
            {
                displalyInfo.displayInfoMain(ex.StackTrace);
            }

        }

        private void cbo_type_selectType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbo_type_selectType.SelectedIndex > -1)
            {
                var strSelect = cbo_type_selectType.Text;
                var tList = GlobalVar.tv_list.Where(a => a.type == strSelect).ToList();
                if (tList.Count > 0)
                {
                    if (((ComboBox)sender).Name == "cbo_type_selectType")
                    {
                        var strVersion11 = cbo_selectVersion.Text;
                        var arrVer = GlobalVar.tv_list.Where(a => a.type == cbo_type_selectType.Text).Select(a => a.Version).Distinct().ToArray();
                        cbo_selectVersion.Items.Clear();
                        cbo_selectVersion.Items.AddRange(arrVer);
                        if (arrVer.Contains(strVersion11))
                            cbo_selectVersion.Text = strVersion11;
                        else
                            cbo_selectVersion.Text = "";
                    }
                    var strVersion = cbo_selectVersion.Text;
                    tempSelectVersion = strSelect + "~" + strVersion;
                }
                
            }
        }
        private string tempSelectVersion = "";
        private void cbo_selectVersion_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbo_type_selectType.SelectedIndex > -1 && cbo_selectVersion.SelectedIndex > -1)
            {
                var strSelect = cbo_type_selectType.Text;
                var strVersion = cbo_selectVersion.Text;
                var tList = GlobalVar.tv_list.Where(a => a.type == strSelect && a.Version == strVersion).ToList();
                if (tList.Count > 0)
                {
                    tempSelectVersion = tList[0].type + GlobalVar.char_VersionSpilt + tList[0].Version;
                }
            }
        }

        private void dgv_type_SelectionChanged(object sender, EventArgs e)
        {
            if(dgv_type.SelectedRows.Count>0)
            {
               var typeName= dgv_type.SelectedRows[0].Cells[1].Value.ToString();
                var lst=GlobalVar.tv_list.Where(a => a.type == typeName).ToList();
                dgv_version.Rows.Clear();
                var rowIndex = 0;
                lst.ForEach(cur =>
                {
                    rowIndex++;
                    dgv_version.Rows.Add(new object[] { rowIndex, cur.type, cur.Version });

                });
            }
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            var curTypename = tbx_typeName.Text;
            var curVersionname = tbx_VersionName.Text;
            if (string.IsNullOrEmpty(curTypename) ||string.IsNullOrEmpty(curVersionname))
            {
                MessageBox.Show("产品名称/产品型号不能为空");
                return;
            }
            var curlist=GlobalVar.tv_list.Where(a => a.type == curTypename && a.Version == curVersionname).ToList();
            if(curlist.Count>0)
            {
                MessageBox.Show("产品名称 产品型号  已存在  添加失败");
                return;
            }
            var typeVersion = curTypename + GlobalVar.char_VersionSpilt + curVersionname;
            bool IsAddOK = true;
            if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
            {
                IsAddOK = false;
                if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_GetModelInfo))
                {
                    var res = UploadInterface.upload_GetModelInfo();
                    if (res != null && res.Code == "00" && res.ModelInfoList != null && res.ModelInfoList.Count > 0)
                    {
                        var mlst = res.ModelInfoList.Where(a => a.Model == curTypename).ToList();
                        if (mlst != null && mlst.Count > 0)
                        {
                            var curVer = curVersionname;
                            var curConfig = "";
                            if (curVersionname.IndexOf(" ") > 0)
                            {
                                curVer = curVersionname.Split(' ')[0];
                                curConfig = curVersionname.Split(' ')[1];
                            }
                            var vlst = mlst[0].ModelVerInfoList.Where(a => a.Ver == curVer && a.Config == curConfig).ToList();
                            if (vlst != null && vlst.Count > 0)
                            {
                                IsAddOK = true;
                            }
                        }
                    }
                }
            }
            if (IsAddOK)
            {
                if (DialogResult.Yes == MessageBox.Show($"确认要新增产品{curTypename}版本号{curVersionname}吗?", "询问", MessageBoxButtons.YesNo))
                {
                    displalyInfo.displayInfoMain($"确认新增{typeVersion}");
                    var nOK = CopyToNewType(typeVersion);
                    if (nOK == 1)
                        GlobalVar.tv_list.Add(new typeVersion()
                        {
                            type = curTypename,
                            Version = curVersionname
                        });
                    RefreshTable(typeVersion);

                }
            }
            else
            {
                if(GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                {
                    MessageBox.Show("MES无相关产品版本号   添加失败");
                }
            }
        }
        /// <summary>
        ///   //新增的要拷贝文件  配置文件+ROI文件夹+Template文件夹
        /// </summary>
        /// <param name="newtypeVersion"></param>
        private int CopyToNewType(string newtypeVersion)
        {
            try
            {
                //  配置文件
                var path_typeCur= GlobalVar.type_path + "\\" + GlobalVar.closeSave.CurrentTypeName + ".tfp";
                var path_typeNew = GlobalVar.type_path + "\\" + newtypeVersion + ".tfp";
                if(File.Exists(path_typeCur)&&!File.Exists(path_typeNew))
                File.Copy(path_typeCur, path_typeNew);
                //ROI文件夹
                var dir_ROICur =visionProc.roiDir + $"\\{GlobalVar.closeSave.CurrentTypeName}";
                var dir_typeNew = visionProc.roiDir + $"\\{newtypeVersion}";
                if (Directory.Exists(dir_ROICur) && !Directory.Exists(dir_typeNew))
                {
                    Directory.CreateDirectory(dir_typeNew);
                    var files = Directory.GetFiles(dir_ROICur);
                    for(int i=0; i< files.Length;i++)
                    {
                        var newfilePath = files[i].Replace(dir_ROICur, dir_typeNew);
                        File.Copy(files[i], newfilePath);
                    }
                }

                //Template文件夹
                var dir_TempCur = visionProc.TemplateRoiDir + $"\\{GlobalVar.closeSave.CurrentTypeName}";
                var dir_TempNew = visionProc.TemplateRoiDir + $"\\{newtypeVersion}";
                if (Directory.Exists(dir_TempCur) && !Directory.Exists(dir_TempNew))
                {
                    Directory.CreateDirectory(dir_TempNew);
                    var files = Directory.GetFiles(dir_TempCur);
                    for (int i = 0; i < files.Length; i++)
                    {
                        var newfilePath = files[i].Replace(dir_TempCur, dir_TempNew);
                        File.Copy(files[i], newfilePath);
                    }
                }
                return 1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain(ex.Message);
                return -1;
            }
        }
        /// <summary>
        ///   //新增的要拷贝文件  配置文件+ROI文件夹+Template文件夹
        /// </summary>
        /// <param name="newtypeVersion"></param>
        private int DeleteFile(string typeVersion_delete)
        {
            try
            {
                //  配置文件
                var path_typeDelete = GlobalVar.type_path + "\\" + typeVersion_delete + ".tfp";
                if (File.Exists(path_typeDelete) )
                    File.Delete(path_typeDelete);
                //ROI文件夹
                var dir_typeDelete = visionProc.roiDir + $"\\{typeVersion_delete}";
                if (Directory.Exists(dir_typeDelete) )
                    Directory.Delete(dir_typeDelete,true);
                //Template文件夹
                var dir_tempDelete = visionProc.TemplateRoiDir + $"\\{typeVersion_delete}";
                if (Directory.Exists(dir_tempDelete))
                    Directory.Delete(dir_tempDelete, true);
                return 1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain(ex.Message);
                return -1;
            }
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            var curTypename = tbx_typeName.Text;
            var curVersionname = tbx_VersionName.Text;
            if (string.IsNullOrEmpty(curTypename) || string.IsNullOrEmpty(curVersionname))
            {
                MessageBox.Show("产品名称/产品型号不能为空");
                return;
            }
            var curlist = GlobalVar.tv_list.Where(a => a.type == curTypename && a.Version == curVersionname).ToList();
            if (curlist.Count== 0)
            {
                MessageBox.Show("产品名称 产品型号  不存在 删除失败");
                return;
            }
            var typeVersion = curTypename + GlobalVar.char_VersionSpilt + curVersionname;
            if(GlobalVar.closeSave.CurrentTypeName== typeVersion)
            {
                MessageBox.Show("当前配置正在使用中  不能删除");
                return;
            }
            if(GlobalVar.tv_list.Count==1)
            {
                MessageBox.Show("至少留下一个配方版本  不能删除");
                return;
            }
            if (DialogResult.Yes == MessageBox.Show($"确认要删除产品{curTypename}版本号{curVersionname}吗?", "询问", MessageBoxButtons.YesNo))
            {
                displalyInfo.displayInfoMain($"确认删除{typeVersion}");
                var nOK = DeleteFile(typeVersion);
                if (nOK == 1)
                {
                    GlobalVar.tv_list.RemoveAll(a => a.type == curTypename && a.Version == curVersionname);
                }
                RefreshTable(typeVersion);
            }
        }

        private void btn_changeTypeVersion_Click(object sender, EventArgs e)
        {
            var curType = cbo_type_selectType.Text.Trim();
            var curVersion = cbo_selectVersion.Text.Trim();
            if (!string.IsNullOrEmpty(curType) && !string.IsNullOrEmpty(curVersion))
            {
                if (MessageBox.Show("请确认目前设备上的工装是否已更换   工艺参数已确认并正式生产?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                    {
                        if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_GetModelInfo))
                        {
                            var res = UploadInterface.upload_GetModelInfo();
                            if (res != null && res.Code == "00" && res.ModelInfoList != null && res.ModelInfoList.Count > 0)
                            {
                                var mlst = res.ModelInfoList.Where(a => a.Model == curType).ToList();

                                if (mlst != null && mlst.Count > 0)
                                {
                                    var curVer = curVersion;
                                    var curConfig = "";
                                    if (curVersion.IndexOf(" ") > 0)
                                    {
                                        curVer = curVersion.Split(' ')[0];
                                        curConfig = curVersion.Split(' ')[1];
                                    }
                                    var vlst = mlst[0].ModelVerInfoList.Where(a => a.Ver == curVer && a.Config == curConfig).ToList();
                                    if (vlst != null && vlst.Count > 0)
                                    {
                                        bool isAdd = false;
                                        if (!cbo_type_selectType.Items.Contains(curType))
                                        {
                                            isAdd = true;
                                            cbo_type_selectType.Items.Add(curType);
                                            cbo_selectVersion.Items.Clear();
                                        }
                                        if (!cbo_selectVersion.Items.Contains(curVersion))
                                        {
                                            isAdd = true;
                                            cbo_selectVersion.Items.Add(curVersion);
                                        }
                                        if (isAdd)
                                            GlobalVar.tv_list.Add(new typeVersion() { type = curType, Version = curVersion });
                                        ChangeType(tempSelectVersion);
                                        GlobalVar.ChangeModel(tempSelectVersion);
                                        displalyInfo.displayInfoMain($"版本切换为{ GlobalVar.closeSave.CurrentTypeName }");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        bool isAdd = false;
                        if (!cbo_type_selectType.Items.Contains(curType))
                        {
                            cbo_type_selectType.Items.Add(curType);
                            cbo_selectVersion.Items.Clear();
                            isAdd = true;
                        }
                        if (!cbo_selectVersion.Items.Contains(curVersion))
                        {
                            cbo_selectVersion.Items.Add(curVersion);
                            isAdd = true;

                        }
                        if (isAdd)
                            GlobalVar.tv_list.Add(new typeVersion() { type = curType, Version = curVersion });
                        ChangeType(tempSelectVersion);
                        GlobalVar.ChangeModel(tempSelectVersion);
                        displalyInfo.displayInfoMain($"版本切换为{ GlobalVar.closeSave.CurrentTypeName }");
                        displalyInfo.displayInfoMain("型号保存成功");
                    }
                }
                   
            }
        }
        PageTypeSetting pageForm;
        private void cbo_selectVersion_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            panel2.Visible = false;
            return;
            if (!string.IsNullOrEmpty(tempSelectVersion) && tempSelectVersion.Contains("~"))
            {
                if (pageForm != null && !pageForm.IsDisposed)
                    pageForm.Close();
                pageForm = new PageTypeSetting(tempSelectVersion);
                pageForm.TopLevel = false;
                pageForm.FormBorderStyle = FormBorderStyle.None;
                pageForm.Parent = panel2;
                pageForm.Dock = DockStyle.Fill;
                pageForm.Show();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var curType = cbo_type_selectType.Text.Trim();
            var curVersion = cbo_selectVersion.Text.Trim();
            if (string.IsNullOrEmpty(curType) || string.IsNullOrEmpty(curVersion))
            {
                return;
            }
            var curlist = GlobalVar.tv_list.Where(a => a.type == curType && a.Version == curVersion).ToList();
            if (curlist.Count < 1)
            {
                MessageBox.Show("产品名称 产品型号 不存在");
                return;
            }
            //if (curlist[0].GetTypeVersion() == GlobalVar.closeSave.CurrentTypeName)
            //{
            //    MessageBox.Show("产品名称 产品型号 不存在");
            //    return;
            //}
            if (GlobalVar.isAutoRun)
            {
                MessageBox.Show("机器自动状态下不能导入产品");
                return;
            }

            string strPath = curlist[0].GetTypeVersion();
            string newPath = $"{GlobalVar.type_path}//{strPath}.tfp";

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "All File(*.*)|*.*";
            ofd.Title = "选择打印模板文件";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string selectName = ofd.FileName;
                try
                {
                    if (File.Exists(newPath))
                    {
                        if (MessageBox.Show($"是否替换当前文件：{newPath}", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            File.Delete(newPath);
                            File.Copy(selectName, newPath);

                            //GlobalVar.ChangeModel(strPath);
                            MessageBox.Show("参数导入成功！");
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

        }
    }
}
